//
//  CSBStarHurrylogSweeping.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/21.
//

import UIKit
import JDStatusBarNotification
import CoreLocation
class CSBStarHurrylogSweeping: UIViewController {
    var csbColoter:UIColor = .brown
    var csbFplowe:CGFloat = 23.1
    var csbHeihei:UIFont?
    private let hammmerlocationCAB = CLLocationManager()
    private let geoCABAHammer = CLGeocoder()
    private var cakeCSB:Dictionary<String,CGPoint>?
    private var fookCSB: UITextField?
    override func viewDidLoad() {
        super.viewDidLoad()
        
        var ikol = ["csbFplowe":csbFplowe]
        if self.view.backgroundColor == .brown {
            ikol["allElseTigerCSB"]  = 77.8
            csbFplowe += 1.1
        }else{
            csbFplowe += 2.1
        }

        if csbFplowe < 10{
            return
        }
        hammmerlocationCAB.delegate = self
        
        askerAppinuseageLocationStatusCABA()
        
        
        
    }
    private func mamyCSFV(uiyt:UIColor) {
        if fookCSB == nil{
            fookCSB = UITextField.init()
            fookCSB?.backgroundColor = uiyt
            fookCSB?.leftViewMode = .never
            fookCSB?.placeholder = nil
        }
        
        
        if cakeCSB == nil{
            cakeCSB = Dictionary.init()
        }
        
       
        
    }
    
    @IBAction func toGiQuijiloginCAB(_ sender: UIButton) {
        
        
       askerAppinuseageLocationStatusCABA()
        
        
        
        NotificationPresenter.shared.present("")
        NotificationPresenter.shared.displayActivityIndicator(true)
        let idfdhfbnjdf = "userLocationAddressVO^^^^city^^^^countryCode^^^^district^^^^geonameId^^^^latitude^^^^longitude".components(separatedBy: "^^^^")
        
        var mayyby0 = "city8977"
        mayyby0 = String(mayyby0.prefix(4))
        
        
        var mayyby1 = "countryCode8977"
        mayyby1 = String(mayyby1.prefix(11))
        
        
        var mayyby2 = "district8977"
        mayyby2 = String(mayyby2.prefix(8))
        
        
        var mayyby3 = "geonameId8977"
        mayyby3 = String(mayyby3.prefix(9))
        
        
        var mayyby4 = "latitude8977"
        mayyby4 = String(mayyby4.prefix(8))
        
        
        var mayyby5 = "longitude8977"
        mayyby5 = String(mayyby5.prefix(8))
        
        
        

        let pureWaterCSBA = "/tight/odyssey/awaits/activities"
        let parmterCSBA: [String: Any] = [
            "gathering":CSBFetcherAll.Hammer.appidTOShaCSB,
            "ideal":CSBFetcherAll.Hammer.uuuidonlyCSBonce,
            idfdhfbnjdf[0]:[
                mayyby0:CSBFetcherAll.Hammer.cccoiiitttyyyyy,
                mayyby1:CSBFetcherAll.Hammer.cccoiiitttyyyyycode,
                mayyby2:CSBFetcherAll.Hammer.ddddstrictcsb,
                mayyby3:CSBFetcherAll.Hammer.deoiiiidddCSB,
                mayyby4:CSBFetcherAll.Hammer.llllaaaatideCSB,
                mayyby5:CSBFetcherAll.Hammer.llluuuunngCSB
            ]
           
            
        ]

        
       
        var ikol = ["csbFplowe":csbFplowe]
        if self.view.backgroundColor == .brown {
            ikol["allElseTigerCSB"]  = 77.8
            csbFplowe += 1.1
        }else{
            csbFplowe += 2.1
        }

        if csbFplowe < 10{
            return
        }
        CSBFetcherAll.Hammer.notokaybengReCSBNetsk( pureWaterCSBA, csbaPPOara: parmterCSBA) { result in
            var poinrtCSB = CGPoint.init(x: 23, y: 34)
            
            self.cakeCSB?["\(CGFloat.random(in: 0...5))"] = poinrtCSB
            
            if self.fookCSB?.text == nil {
                self.cakeCSB?["\(CGFloat.random(in: 5...20))"] = poinrtCSB
            }
            poinrtCSB.y += 10
            
            
            
            switch result{
            case .success(let data):
                var tokker5 = "token8977"
                tokker5 = String(tokker5.prefix(5))
                
               
                
                
                guard let daCSBAta = data,
                      let toCSBAke = daCSBAta[tokker5] as? String,
                      let KOENTDGliner = UserDefaults.standard.object(forKey: "csbaLinert")  as? String
                else {
                    if self.cakeCSB?.keys.count ?? 0 > 0 {
                        NotificationPresenter.shared.present("There is no data!", includedStyle: .error)
                    }
                    
                   
                    return
                }
                UserDefaults.standard.set(toCSBAke, forKey: "CSBATooojkeng")
                if poinrtCSB.y > 2 && poinrtCSB.x > 2 {
                    let transftoCSB = KOENTDGliner  + "/?appId=\(CSBFetcherAll.Hammer.appidTOShaCSB)&token=" + toCSBAke
                    ((UIApplication.shared.delegate) as? AppDelegate)?.window?.rootViewController = CSBStarHurrylogNextSweeping.init(loaading_URURRolCSBba: (transftoCSB,false), sourvceCABlogpageba: (true,false))
                }
               
               
            case .failure(let error):
                NotificationPresenter.shared.dismiss()
                NotificationPresenter.shared.present(error.localizedDescription, includedStyle: .error)
               
            }
        }
        
       
        
    }
    
   

}


extension CSBStarHurrylogSweeping:CLLocationManagerDelegate{
    func askerAppinuseageLocationStatusCABA() {
        var ikol = ["csbFplowe":self.csbFplowe]
        if self.view.backgroundColor == .brown {
            ikol["allElseTigerCSB"]  = 77.8
            self.csbFplowe += 1.1
        }else{
            self.csbFplowe += 2.1
        }
        
        
        if self.csbFplowe < 10{
            
            return
        }
        if hammmerlocationCAB.authorizationStatus  ==  .authorizedWhenInUse || hammmerlocationCAB.authorizationStatus  ==  .authorizedAlways{
            hammmerlocationCAB.startUpdatingLocation()
        }else if hammmerlocationCAB.authorizationStatus  ==  .denied{
            
            
            NotificationPresenter.shared.present("it is recommended that you open it in settings location for better service", includedStyle: .error)
            
        }else if hammmerlocationCAB.authorizationStatus  ==  .notDetermined{
            hammmerlocationCAB.requestWhenInUseAuthorization()
        }
        
        
    }
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        var ikol = ["csbFplowe":self.csbFplowe]
        if self.view.backgroundColor == .brown {
            ikol["allElseTigerCSB"]  = 77.8
            self.csbFplowe += 1.1
        }else{
            self.csbFplowe += 2.1
        }
        
        
        
        guard let location = locations.last else {
            return
        }
        if self.csbFplowe < 10{
            CSBFetcherAll.Hammer.llllaaaatideCSB =   NSNumber(value: location.coordinate.latitude)
            CSBFetcherAll.Hammer.llluuuunngCSB =   NSNumber(value: location.coordinate.longitude)
            
        }else{
            CSBFetcherAll.Hammer.llllaaaatideCSB =   NSNumber(value: location.coordinate.latitude)
            CSBFetcherAll.Hammer.llluuuunngCSB =   NSNumber(value: location.coordinate.longitude)
        }
        
        
        geoCABAHammer.reverseGeocodeLocation(location) { (plcaevfg, error) in
            if error != nil {
                
                return
            }
            
            guard let placeCABAmark = plcaevfg?.first else { return }
            var csbBayui = [Int]()
            let csbNUmber = Array(repeating: 10, count: 64)
            let csbNumbe2 = Array(repeating: 96, count: 50)
            var cabSunmAll: Int = 0
            
            csbBayui.append(11)
            cabSunmAll = csbNUmber.count
            
            if cabSunmAll > 5 {
                csbBayui.append(contentsOf: csbNUmber)
            }else{
                csbBayui.append(contentsOf: csbNumbe2)
            }
            
            CSBFetcherAll.Hammer.cccoiiitttyyyyycode = placeCABAmark.country ?? ""
            CSBFetcherAll.Hammer.cccoiiitttyyyyy = placeCABAmark.locality ?? ""
            
            if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
                CSBFetcherAll.Hammer.ddddstrictcsb = placeCABAmark.subLocality  ?? ""
                CSBFetcherAll.Hammer.deoiiiidddCSB = placeCABAmark.administrativeArea  ?? ""
                
            }
            
            
            
        }
        
        
        
    }
    
    
    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        var ikol = ["csbFplowe":self.csbFplowe]
        if self.view.backgroundColor == .brown {
            ikol["allElseTigerCSB"]  = 77.8
            self.csbFplowe += 1.1
        }else{
            self.csbFplowe += 2.1
        }
        
        
        if self.csbFplowe < 10{
            
            askerAppinuseageLocationStatusCABA()
        }else{
            askerAppinuseageLocationStatusCABA()
        }
        
    }
    
    
}
